﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MLGest.Models;
using MLGest.Library;

namespace MLGest.Controllers
{
    public class HomeController : Controller
    {
        string strVersionServicio = ControlVersion.obtenerVersion();
        string strEstiloGeneral = " Color:Blue; ";
        [HttpGet]
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            ViewBag.VersionServicio = strVersionServicio;
            ViewBag.HeaderTitle = "MLGest - Ver: " + strVersionServicio + " - Sistema de gestión integral para Mym Importaciones";
            ViewBag.strEstiloGeneral = strEstiloGeneral;
            ViewBag.ErrorAMostrar = "";
            
            return View();
        }
        [HttpPost]
        public ActionResult Index(LogInModel objModel)
        {     
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            ViewBag.VersionServicio = strVersionServicio;
            ViewBag.HeaderTitle = "MLGest - Ver: " + strVersionServicio + " - Sistema de gestión integral para Mym Importaciones";
            ViewBag.strEstiloGeneral = strEstiloGeneral;
            ViewBag.ErrorAMostrar = "";

            switch (objModel.strButtons)
            {
                case "Registrarse":
                    #region LOGIN
                      if (objModel.strPassword == null)
                        {
                            ViewBag.ErrorAMostrar = "Por favor ingrese el password";
                            ViewData["loginError"] = true;
                            ViewData["loginErrorTypeError"] = true;
                            return View(objModel);
                        }
                        if (objModel.strUsuario == null)
                        {
                            ViewBag.ErrorAMostrar = "Por favor ingrese el usuario";
                            ViewData["loginError"] = true;
                            ViewData["loginErrorTypeError"] = true;
                            return View(objModel);
                        }
                        else
                        {
                            objModel.objRol = enumRolUsuario.Administrador;

                            ControlNovedad objNovedad = new ControlNovedad();
                            
                            objNovedad.agregarNovedad("HOLA");
                            objNovedad.agregarNovedad("CHAU");
                            objNovedad.agregarNovedad("OK");

                            ViewBag.MyHTMLTest = objNovedad.obtenerCartelDeNovedades();

                            ViewData["loginUserHasPhoto"] = false;
                            ViewData["loginUserRole"] = objModel.objRol;
                            ViewData["loginUserName"] = objModel.strUsuario.ToString();
                            return View("Start"); 
                        }
                    #endregion
                    break;
                case "Cerrar Sesión":
                    #region LOGOUT
                        ViewData["loginError"] = true;
                        ViewData["loginErrorTypeOk"] = true;
                        ViewBag.ErrorAMostrar = "Usted cerró la sesión correctamente";
                        ViewData["loginUserName"] = null;
                        ViewData["loginUserRole"] = null;
                        return View("Index"); 
                    #endregion
                    break;
                case "ABMPersonal":
                    #region ABM PERSONAL                    
                    return RedirectToAction("ABM_Personal", "ABM_Personal", null);
                    
                    #endregion
                    break;
                case "ABMVentas":
                    #region ABM VENTAS
                     return RedirectToAction("Ventas", "Ventas", null);
                    #endregion
                    break;
                case "ABMCompras":
                    #region ABM COMPRAS
                    return RedirectToAction("ABM_Compras", "ABM_Compras", null);
                    #endregion
                    break;
                case "ABMProductos":
                    #region ABM PRODUCTOS
                    return RedirectToAction("Productos", "Productos", null);
                    #endregion
                    break;
                default:
                    return View("Index");
                    break;
            }
          
            
        }


        public ActionResult About()
        {
            ViewBag.VersionServicio = strVersionServicio;
            return View();
        }
    }

}
